package top.whysu.rongcloud.api;

import io.rong.methods.chatroom.Chatroom;
import io.rong.methods.conversation.Conversation;
import io.rong.methods.message.Message;
import io.rong.methods.sensitive.SensitiveWord;
import io.rong.methods.sensitive.Wordfilter;
import io.rong.methods.user.User;
import io.rong.util.HostType;
import top.whysu.rongcloud.api.dto.GroupSync;

import java.util.concurrent.ConcurrentHashMap;

public class RongCloudSMS {
    private static ConcurrentHashMap<String, RongCloudSMS> RongCloudSMS = new ConcurrentHashMap();
    public User user;
    public Message message;
    public Wordfilter wordfilter;
    public SensitiveWord sensitiveword;
    public Groups groups;
    public GroupSync groupSync;
    public Chatroom chatroom;
    public Chatrooms chatrooms;
    public Conversation conversation;
    private HostType apiHostType = new HostType("http://api.cn.ronghub.com");
    private HostType smsHostType = new HostType("http://api.sms.ronghub.com");

    public HostType getApiHostType() {
        return this.apiHostType;
    }

    public void setApiHostType(HostType apiHostType) {
        this.apiHostType = apiHostType;
    }

    public HostType getSmsHostType() {
        return this.smsHostType;
    }

    public void setSmsHostType(HostType smsHostType) {
        this.smsHostType = smsHostType;
    }

    private RongCloudSMS(String appKey, String appSecret) {
        this.chatrooms = new Chatrooms(appKey, appSecret);
        this.chatrooms.setRongCloudSMS(this);
        this.groups = new Groups(appKey, appSecret);
        this.groups.setRongCloud(this);

    }

    public static RongCloudSMS getInstance(String appKey, String appSecret) {
        if (null == RongCloudSMS.get(appKey)) {
            RongCloudSMS.putIfAbsent(appKey, new RongCloudSMS(appKey, appSecret));
        }

        return (RongCloudSMS)RongCloudSMS.get(appKey);
    }

    public static RongCloudSMS getInstance(String appKey, String appSecret, String api) {
        if (null == RongCloudSMS.get(appKey)) {
            RongCloudSMS rc = new RongCloudSMS(appKey, appSecret);
            if (api != null && api.trim().length() > 0) {
                rc.setApiHostType(new HostType(api));
            }

            RongCloudSMS.putIfAbsent(appKey, rc);
        }

        return (RongCloudSMS)RongCloudSMS.get(appKey);
    }
}
